const { getUGM } = require('../../handleData')

function handleData(data) {
  if (!data) return
  const ugm = data.ugm
  console.log('加载UGM')
  const cols = {}
  const docs = {}
  if (ugm.bim) {
    return {
      cols: { ...ugm.data.cols, ...ugm.bim.cols },
      docs: { ...ugm.data.docs, ...ugm.bim.docs },
      architectureMD5: ugm.architectureMD5,
      structureMD5: ugm.structureMD5,
      isUGM: true
    }
  } else {
    const nodes = ugm.elements.nodes
    for (let i = 0; i < nodes.length; i++) {
      let node = nodes[i]
      if (node.data) node = node.data
      node.definition = node.definition.toLowerCase()
      docs[node.id] = node
    }
    for (const key in docs) {
      const node = docs[key]
      const definition = node.definition
      if (definition) {
        if (!cols[definition]) cols[definition] = []
        cols[definition].push(node)
      }
    }
    return {
      cols,
      docs,
      architectureMD5: ugm.architectureMD5,
      structureMD5: ugm.structureMD5,
      isUGM: true
    }
  }
}

export { handleData, getUGM }
